package com.bai.jwt.service;

import com.bai.jwt.mapper.UserMapper;
import com.bai.jwt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

@Service
@Transactional
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public User findUserById(String userId) {
        Example example = new Example(User.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("id",userId);
        return userMapper.selectOneByExample(example);
    }

    public User findByUsername(User user) {
        Example example = new Example(User.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("username",user.getUsername());
        return userMapper.selectOneByExample(example);
    }

}
